1、C#操作sqlite本地数据库; 2、可以录入自己喜欢的英语单词,打造出属于自己的英语词典。主要是C#对本地数据库sqlite的操作演练
using CC.BLL;using CC.Helper;using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace translate{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } /// <summary> /// 录入 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button2_Click(object sender, EventArgs e) { save(); } private void save() { try { if (!h_encrypt.HasHanz(textBox1.Text)) { new b_en_ch().save(textBox1.Text, textBox2.Text, textBox3.Text); MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); clear(); } } catch (Exception ex) { h_mylog.WriteLog(ex, "Form1.cs", "button2_Click"); } } /// <summary> /// 查询 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { search(); } private void search() { try { clear(); DataTable dt = null; if (h_encrypt.HasHanz(textBox1.Text)) { dt = new b_en_ch().get_by_ch(textBox1.Text); if (dt != null && dt.Rows.Count == 1) { textBox2.Text = dt.Rows[0]["read"].ToString(); textBox3.Text = dt.Rows[0]["english"].ToString(); } } else { dt = new b_en_ch().get_by_en(textBox1.Text); if (dt != null && dt.Rows.Count == 1) { textBox2.Text = dt.Rows[0]["read"].ToString(); textBox3.Text = dt.Rows[0]["chinese"].ToString(); } } } catch (Exception ex) { h_mylog.WriteLog(ex, "Form1.cs", "search"); } finally { } } private void clear() { textBox2.Text = ""; textBox3.Text = ""; } private void textBox1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { search(); } } private void textBox3_KeyDown(object sender, KeyEventArgs e) { if (e.Control && e.KeyCode == Keys.S) { save(); } } }}
评论